import 'dart:convert';
import 'package:lib_network/http_config.dart';

class BaseResp {
  late int code;
  late String msg;
  // late Map<String, dynamic> data;
  late dynamic data;

  factory BaseResp(jsonStr) => BaseResp.fromJson(jsonStr);

  BaseResp.fromJson(jsonRes) {
    print('jsonRes = ${jsonRes}');
    if (jsonRes is String) {
      //decode
      jsonRes = json.decode(jsonRes);
      // print('jsonRes is  string');
    }

    code = jsonRes[HttpConfig().codeKey];
    msg = jsonRes[HttpConfig().msgKey] ?? "";

    data = jsonRes[HttpConfig().dataKey] ?? {};
    // print('code = ${code}');
    // print('msg = ${msg}');
    // print('data = ${data}');
  }
}
